/**
 * amis v6.13.0
 * build time: 2025-08-12
 * Copyright 2018-2025 baidu
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _Spinner = require('amis-ui/lib/components/Spinner');
var _NotFound = require('amis-ui/lib/components/404');
var _Layout = require('amis-ui/lib/components/Layout');
var _Icon = require('amis-ui/lib/components/Icon');
var _AsideNav = require('amis-ui/lib/components/AsideNav');
var _Html = require('amis-ui/lib/components/Html');
var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _Spinner__default = /*#__PURE__*/_interopDefaultLegacy(_Spinner);
var _NotFound__default = /*#__PURE__*/_interopDefaultLegacy(_NotFound);
var _Layout__default = /*#__PURE__*/_interopDefaultLegacy(_Layout);
var _Icon__default = /*#__PURE__*/_interopDefaultLegacy(_Icon);
var _AsideNav__default = /*#__PURE__*/_interopDefaultLegacy(_AsideNav);
var _Html__default = /*#__PURE__*/_interopDefaultLegacy(_Html);
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
var _J$F_ = (__react_jsx__["default"] || __react_jsx__).Fragment;


;var App = /** @class */function (_super) {
  tslib.__extends(App, _super);
  function App(props) {
    var _this = this;
    var _a, _b, _c;
    _this = _super.call(this, props) || this;
    var store = props.store;
    store.syncProps(props, undefined, ['pages']);
    store.updateActivePage(Object.assign({}, (_a = props.env) !== null && _a !== void 0 ? _a : {}, {
      showFullBreadcrumbPath: (_b = props.showFullBreadcrumbPath) !== null && _b !== void 0 ? _b : false,
      showBreadcrumbHomePath: (_c = props.showBreadcrumbHomePath) !== null && _c !== void 0 ? _c : true
    }));
    if (props.env.watchRouteChange) {
      _this.unWatchRouteChange = props.env.watchRouteChange(function () {
        var _a, _b, _c;
        return store.updateActivePage(Object.assign({}, (_a = props.env) !== null && _a !== void 0 ? _a : {}, {
          showFullBreadcrumbPath: (_b = props.showFullBreadcrumbPath) !== null && _b !== void 0 ? _b : false,
          showBreadcrumbHomePath: (_c = props.showBreadcrumbHomePath) !== null && _c !== void 0 ? _c : true
        }));
      });
    }
    return _this;
  }
  App.prototype.componentDidMount = function () {
    return tslib.__awaiter(this, void 0, void 0, function () {
      var _a, data, dispatchEvent, rendererEvent;
      return tslib.__generator(this, function (_b) {
        switch (_b.label) {
          case 0:
            _a = this.props, data = _a.data, dispatchEvent = _a.dispatchEvent;
            return [4 /*yield*/, dispatchEvent('init', data, this)];
          case 1:
            rendererEvent = _b.sent();
            if (rendererEvent === null || rendererEvent === void 0 ? void 0 : rendererEvent.prevented) {
              return [2 /*return*/];
            }
            this.reload();
            return [2 /*return*/];
        }
      });
    });
  };
  App.prototype.componentDidUpdate = function (prevProps) {
    var _a, _b, _c;
    return tslib.__awaiter(this, void 0, void 0, function () {
      var props, store;
      return tslib.__generator(this, function (_d) {
        props = this.props;
        store = props.store;
        store.syncProps(props, prevProps, ['pages']);
        if (amisCore.isApiOutdated(prevProps.api, props.api, prevProps.data, props.data)) {
          this.reload();
        } else if (props.location && props.location !== prevProps.location) {
          store.updateActivePage(Object.assign({}, (_a = props.env) !== null && _a !== void 0 ? _a : {}, {
            showFullBreadcrumbPath: (_b = props.showFullBreadcrumbPath) !== null && _b !== void 0 ? _b : false,
            showBreadcrumbHomePath: (_c = props.showBreadcrumbHomePath) !== null && _c !== void 0 ? _c : true
          }));
        }
        return [2 /*return*/];
      });
    });
  };
  App.prototype.componentWillUnmount = function () {
    var _a;
    (_a = this.unWatchRouteChange) === null || _a === void 0 ? void 0 : _a.call(this);
  };
  App.prototype.reload = function (subpath, query, ctx, silent, replace) {
    return tslib.__awaiter(this, void 0, void 0, function () {
      var _a, api, store, env, _b, showFullBreadcrumbPath, _c, showBreadcrumbHomePath, locale, json;
      return tslib.__generator(this, function (_d) {
        switch (_d.label) {
          case 0:
            if (query) {
              return [2 /*return*/, this.receive(query, undefined, replace)];
            }
            _a = this.props, api = _a.api, store = _a.store, env = _a.env, _b = _a.showFullBreadcrumbPath, showFullBreadcrumbPath = _b === void 0 ? false : _b, _c = _a.showBreadcrumbHomePath, showBreadcrumbHomePath = _c === void 0 ? true : _c, locale = _a.locale;
            if (!amisCore.isEffectiveApi(api, store.data)) return [3 /*break*/, 2];
            return [4 /*yield*/, store.fetchInitData(api, store.data, {})];
          case 1:
            json = _d.sent();
            if (env.replaceText) {
              json.data = amisCore.replaceText(json.data, env.replaceText, env.replaceTextIgnoreKeys);
            }
            if (json === null || json === void 0 ? void 0 : json.data.pages) {
              json.data = amisCore.envOverwrite(json.data, locale);
              store.setPages(json.data.pages);
              store.updateActivePage(Object.assign({}, env !== null && env !== void 0 ? env : {}, {
                showFullBreadcrumbPath: showFullBreadcrumbPath,
                showBreadcrumbHomePath: showBreadcrumbHomePath
              }));
            }
            _d.label = 2;
          case 2:
            return [2 /*return*/, store.data];
        }
      });
    });
  };
  App.prototype.receive = function (values, subPath, replace) {
    return tslib.__awaiter(this, void 0, void 0, function () {
      var store;
      return tslib.__generator(this, function (_a) {
        store = this.props.store;
        store.updateData(values, undefined, replace);
        return [2 /*return*/, this.reload()];
      });
    });
  };
  /**
   * 支持页面层定义 definitions，并且优先取页面层的 definitions
   * @param name
   * @returns
   */
  App.prototype.resolveDefinitions = function (name) {
    var _a;
    var _b = this.props,
      resolveDefinitions = _b.resolveDefinitions,
      store = _b.store;
    var definitions = (_a = store.schema) === null || _a === void 0 ? void 0 : _a.definitions;
    return (definitions === null || definitions === void 0 ? void 0 : definitions[name]) || resolveDefinitions(name);
  };
  App.prototype.handleNavClick = function (e) {
    e.preventDefault();
    var store = this.props.store;
    var env = this.props.env;
    var link = e.currentTarget.getAttribute('href');
    store.updateOffScreen(false);
    env.jumpTo(link, undefined, this.props.data);
  };
  App.prototype.renderHeader = function () {
    var _a = this.props,
      cx = _a.classnames,
      brandName = _a.brandName,
      header = _a.header,
      render = _a.render,
      store = _a.store,
      logo = _a.logo,
      env = _a.env;
    if (!header && !logo && !brandName) {
      return null;
    }
    return _J$X_(React__default["default"].Fragment, null, _J$X_("div", {
      className: cx('Layout-brandBar')
    }, _J$X_("div", {
      onClick: store.toggleOffScreen,
      className: cx('Layout-offScreenBtn')
    }, _J$X_("i", {
      className: "bui-icon iconfont icon-collapse"
    })), _J$X_("div", {
      className: cx('Layout-brand')
    }, logo && ~logo.indexOf('<svg') ? _J$X_(_Html__default["default"], {
      className: cx('AppLogo-html'),
      html: logo,
      filterHtml: env.filterHtml
    }) : logo ? _J$X_("img", {
      className: cx('AppLogo'),
      src: logo
    }) : _J$X_("span", {
      className: "visible-folded "
    }, brandName === null || brandName === void 0 ? void 0 : brandName.substring(0, 1)), _J$X_("span", {
      className: "hidden-folded m-l-sm"
    }, brandName))), _J$X_("div", {
      className: cx('Layout-headerBar')
    }, _J$X_("a", {
      onClick: store.toggleFolded,
      type: "button",
      className: cx('AppFoldBtn')
    }, _J$X_("i", {
      className: "fa fa-".concat(store.folded ? 'indent' : 'dedent', " fa-fw")
    })), header ? render('header', header) : null));
  };
  App.prototype.renderAside = function () {
    var _this = this;
    var _a = this.props,
      store = _a.store,
      env = _a.env,
      asideBefore = _a.asideBefore,
      asideAfter = _a.asideAfter,
      render = _a.render,
      data = _a.data;
    return _J$X_(React__default["default"].Fragment, null, asideBefore ? render('aside-before', asideBefore) : null, _J$X_(_AsideNav__default["default"], {
      navigations: store.navigations,
      renderLink: function (_a, key) {
        var link = _a.link,
          active = _a.active,
          toggleExpand = _a.toggleExpand,
          cx = _a.classnames,
          depth = _a.depth,
          subHeader = _a.subHeader;
        var children = [];
        if (link.visible === false) {
          return null;
        }
        if (!subHeader && link.children && link.children.some(function (item) {
          return item === null || item === void 0 ? void 0 : item.visible;
        })) {
          children.push(_J$X_("span", {
            key: "expand-toggle",
            className: cx('AsideNav-itemArrow'),
            onClick: function (e) {
              return toggleExpand(link, e);
            }
          }));
        }
        var badge = typeof link.badge === 'string' ? amisCore.filter(link.badge, data) : link.badge;
        badge != null && children.push(_J$X_("b", {
          key: "badge",
          className: cx("AsideNav-itemBadge", link.badgeClassName || 'bg-info')
        }, badge));
        if (!subHeader && link.icon) {
          children.push(_J$X_(_Icon__default["default"], {
            key: "icon",
            cx: cx,
            icon: link.icon,
            className: "AsideNav-itemIcon"
          }));
        } else if (store.folded && depth === 1 && !subHeader) {
          children.push(_J$X_("i", {
            key: "icon",
            className: cx("AsideNav-itemIcon", link.children ? 'fa fa-folder' : 'fa fa-info')
          }));
        }
        children.push(_J$X_("span", {
          className: cx('AsideNav-itemLabel'),
          key: "label"
        }, typeof link.label === 'string' ? amisCore.filter(link.label, data) : link.label));
        return link.path ? /^https?\:/.test(link.path) ? _J$X_("a", {
          target: "_blank",
          key: "link",
          href: link.path,
          rel: "noopener"
        }, children) : _J$X_("a", {
          key: "link",
          onClick: _this.handleNavClick,
          href: link.path || link.children && link.children[0].path
        }, children) : _J$X_("a", {
          key: "link",
          onClick: link.children ? function () {
            return toggleExpand(link);
          } : undefined
        }, children);
      },
      isActive: function (link) {
        return !!env.isCurrentUrl(link === null || link === void 0 ? void 0 : link.path, link);
      }
    }), asideAfter ? render('aside-before', asideAfter) : null);
  };
  App.prototype.renderFooter = function () {
    var _a = this.props,
      render = _a.render,
      footer = _a.footer;
    return footer ? render('footer', footer) : null;
  };
  App.prototype.render = function () {
    var _this = this;
    var _a;
    var _b = this.props,
      cx = _b.classnames,
      store = _b.store,
      render = _b.render,
      _c = _b.showBreadcrumb,
      showBreadcrumb = _c === void 0 ? true : _c,
      loadingConfig = _b.loadingConfig;
    return _J$X_(_Layout__default["default"], {
      header: this.renderHeader(),
      aside: this.renderAside(),
      footer: this.renderFooter(),
      folded: store.folded,
      offScreen: store.offScreen,
      contentClassName: cx('AppContent')
    }, store.activePage && store.schema ? _J$X_(React__default["default"].Fragment, null, showBreadcrumb && store.bcn.length ? _J$X_("ul", {
      className: cx('AppBcn')
    }, store.bcn.map(function (item, index) {
      return _J$X_("li", {
        key: index,
        className: cx('AppBcn-item')
      }, item.path ? _J$X_("a", {
        href: item.path,
        onClick: _this.handleNavClick
      }, item.label) : index !== store.bcn.length - 1 ? _J$X_("a", null, item.label) : item.label);
    })) : null, _J$X_("div", {
      className: cx('AppBody')
    }, render('page', store.schema, {
      key: "".concat((_a = store.activePage) === null || _a === void 0 ? void 0 : _a.id, "-").concat(store.schemaKey),
      data: store.pageData,
      resolveDefinitions: this.resolveDefinitions
    }))) : store.pages && !store.activePage ? _J$X_(_NotFound__default["default"], null, _J$X_("div", {
      className: "text-center"
    }, "\u9875\u9762\u4E0D\u5B58\u5728")) : null, _J$X_(_Spinner__default["default"], {
      loadingConfig: loadingConfig,
      overlay: true,
      show: store.loading || !store.pages,
      size: "lg"
    }));
  };
  App.propsList = ['brandName', 'logo', 'header', 'asideBefore', 'asideAfter', 'pages', 'footer'];
  App.defaultProps = {};
  tslib.__decorate([amisCore.autobind, tslib.__metadata("design:type", Function), tslib.__metadata("design:paramtypes", [String]), tslib.__metadata("design:returntype", void 0)], App.prototype, "resolveDefinitions", null);
  tslib.__decorate([amisCore.autobind, tslib.__metadata("design:type", Function), tslib.__metadata("design:paramtypes", [Object]), tslib.__metadata("design:returntype", void 0)], App.prototype, "handleNavClick", null);
  return App;
}(React__default["default"].Component);
var AppRenderer = /** @class */function (_super) {
  tslib.__extends(AppRenderer, _super);
  function AppRenderer(props, context) {
    var _this = _super.call(this, props) || this;
    var scoped = context;
    scoped.registerComponent(_this);
    return _this;
  }
  AppRenderer.prototype.componentWillUnmount = function () {
    var scoped = this.context;
    scoped.unRegisterComponent(this);
    _super.prototype.componentWillUnmount.call(this);
  };
  AppRenderer.prototype.setData = function (values, replace) {
    return this.props.store.updateData(values, undefined, replace);
  };
  AppRenderer.prototype.getData = function () {
    var store = this.props.store;
    return store.data;
  };
  AppRenderer.contextType = amisCore.ScopedContext;
  AppRenderer = tslib.__decorate([amisCore.Renderer({
    type: 'app',
    storeType: amisCore.AppStore.name
  }), tslib.__metadata("design:paramtypes", [Object, Object])], AppRenderer);
  return AppRenderer;
}(App);

exports.App = App;
exports["default"] = AppRenderer;
